package com.fenda.mybleapplication.study.model;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

public class ViewModelLive extends ViewModel {
    private MutableLiveData<Integer> ATeamScore;
    private MutableLiveData<Integer> BTeamScore;

    private int aBack,bBack;

    public MutableLiveData<Integer> getATeamScore() {
        if (ATeamScore == null){
            ATeamScore = new MutableLiveData<>();
            ATeamScore.setValue(0);
        }
        return ATeamScore;
    }

    public MutableLiveData<Integer> getBTeamScore() {
        if (BTeamScore == null){
            BTeamScore = new MutableLiveData<>();
            BTeamScore.setValue(0);
        }
        return BTeamScore;
    }

    public void addAScore(int score){
        aBack = ATeamScore.getValue();
        bBack = BTeamScore.getValue();
        ATeamScore.setValue(aBack + score);
    }

    public void addBScore(int score){
        aBack = ATeamScore.getValue();
        bBack = BTeamScore.getValue();
        BTeamScore.setValue(bBack + score);
    }

    public void reset() {
        aBack = ATeamScore.getValue();
        bBack = BTeamScore.getValue();
        ATeamScore.setValue(0);
        BTeamScore.setValue(0);
    }

    public void unDo(){
        ATeamScore.setValue(aBack);
        BTeamScore.setValue(bBack);
    }

}
